package org.example.BQ;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class synchronousQueue {
    public static void main(String[] args) {
        SynchronousQueue s  = new SynchronousQueue();

        // 添加线程
        new Thread(()->{
            try {

                s.put(1);

                System.out.println(Thread.currentThread().getName()+"put 1");
                s.put(2);
                System.out.println(Thread.currentThread().getName()+"put 2");
                s.put(3);
                System.out.println(Thread.currentThread().getName()+"put 3");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"A").start();

        // 删除线程
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName()+"-->"+s.take());
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName()+"-->"+s.take());
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName()+"-->"+s.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"B").start();
    }
}
